/*
 * timeout.h
 *
 *  Created on: 2008-11-30
 *      Author: root
 */

#ifndef TIMEOUT_H_
#define TIMEOUT_H_

#include <sys/select.h>

/* According to earlier standards */
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

/*
 * 实现超时功能
 */
int readReady(int fd, int sec, int usec)
{
	struct timeval stTimeOut;
	stTimeOut.tv_sec = sec;
	stTimeOut.tv_usec = usec;

	fd_set rset;
	FD_SET(fd, &rset);
	return (select(fd + 1, &rset, NULL, NULL, &stTimeOut));
}

#endif /* TIMEOUT_H_ */
